package com.link2room.aeriabots.controller.api;

import com.link2room.aeriabots.dto.param.base.WxComponentParamDto;
import com.link2room.aeriabots.facade.IWXComponentFacadeService;
import com.link2room.common.dto.result.base.BaseResultDto;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 发起网页授权获得code
 * Created by LN on 2016/9/7.
 */
@Api(tags ={"微信网页授权"} )
@RestController
@RequestMapping("/api/AccesscodeURL")
public class WxWebAuthenticationAccessCodeApiController {
    @Resource
    private IWXComponentFacadeService wxComponentFacadeService;
    @ApiOperation(value="微信公众号网页授权URL",response = String .class)
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "回调地址",required = true,value = "回调地址", dataType = "String",paramType="query"),
            @ApiImplicitParam(name = "授权类型",required = true,value = "snsapi_base", dataType = "String",paramType="query")
    })
    @RequestMapping(method = RequestMethod.GET)
    public BaseResultDto getAccessCode(
            @RequestParam(name = "redirectUrl",required = true) String redirectUrl ,
            @RequestParam(name = "scope")String scope
    ) throws Exception {
        WxComponentParamDto param = new WxComponentParamDto();
        param.setRedirectURL(redirectUrl);
        param.setScope(scope);
        String url = wxComponentFacadeService.getAccessCodeURL(param);
        BaseResultDto resultDto = new BaseResultDto();
        resultDto.setResultCode(0);
        resultDto.setResultInfo(url);
        return resultDto;
    }
}
